<!DOCTYPE html>
<html>
    <head>
        <title>Leo's Dictionary</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script>
            var xmlhttp;
            var timer;
            
            if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            
            
            function focusText() {
                document.getElementById("english").focus();
            }
            
            function query() {                
                var word = document.getElementById("english").value;                
                
                if (word == "") {
                    document.getElementById("showResult").innerHTML = "";
                } else {
                    xmlhttp.onreadystatechange = showResult;
                    xmlhttp.open("POST","Query",true);
                    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                    xmlhttp.send("word=" + word);
                }
            }            
            
            function showResult() {
                if (xmlhttp.readyState==4 && xmlhttp.status==200) {                    
                    document.getElementById("showResult").innerHTML = xmlhttp.responseText;
                }
            }
            
            function setTimer() {
                clearTimeout(timer);
                timer = setTimeout("query()", 800);
            }
        </script>

        <style type="text/css">
            .center {
                margin: 0 auto;
                width: 350px;
            }
            
            #english {
                font-size: 16px;
                width: 350px;
                height: 24px;                
                padding: 4px 10px;
            }
            #showResult {
                width: 350px;
                padding: 4px 10px;                
            }

        </style>
    </head>
    <body onload="focusText()">
        <div class="center">
            <input type="text" id="english"  onkeyup="setTimer()"/>
            <div id="showResult"></div>
        </div>
    </body>
</html>
